//
//  LogicTest.cpp
//  NanoOSX
//
//  Created by Jeppe Nielsen on 9/21/13.
//  Copyright (c) 2013 Jeppe Nielsen. All rights reserved.
//
#include "Engine.hpp"
#include "GameWorld.hpp"
#include "Vector3.hpp"

using namespace Nano;
using namespace std;

// define our components (data only)
Component(Position)
public:
    Vector3 Position;
};

Component(Velocity)
public:
    Vector3 Velocity;
};

//define our system (logic only)
class PositionUpdater : public GameSystem {
public:
    void Initialize() {
        AddComponent<Position>();
        AddComponent<Velocity>();
    }
    void Update(float dt) {
        for(ObjectCollection::const_iterator iterator = Objects().begin(); iterator!=Objects().end(); ++iterator) {
            GameObject* object = *iterator;
            object->GetComponent<Position>()->Position += object->GetComponent<Velocity>()->Velocity * dt;
        }
    }
};

class Logic : public GameState<Logic> {
    GameWorld world;
    GameObject* object;
    
    void Initialized() {
        world.CreateSystem<PositionUpdater>();
        
        object = world.CreateObject();
        object->AddComponent<Position>();
        object->AddComponent<Velocity>();
        
        object->GetComponent<Position>()->Position = Vector3(0,0,0);
        object->GetComponent<Velocity>()->Velocity = Vector3(0,1,0);
    }
    void Update(float dt) {
        world.Update(dt);
        cout<<object->GetComponent<Position>()->Position<<endl;
    }
};


/*
int main() {
    Engine e;
    e.Start<Logic>();
}
*/